(library (lib logger)
  (export debug info warning error make-prefixed-log-proc)
  (import
    (except (rnrs base) let-values map error)
    (only (guile)
          lambda* λ
          simple-format
          current-output-port
          call-with-output-string)
    (ice-9 textual-ports)
    (lib string-procs)))


(define log-prefixed
  (lambda* (str prefix #:optional (output-port (current-output-port)))
    (put-string output-port
                (string-format "~a: ~a\n" prefix str))))


(define make-prefixed-log-proc
  (λ (the-prefix)
    (lambda* (str #:optional (output-port (current-output-port)))
      (log-prefixed str the-prefix output-port))))


(define debug (make-prefixed-log-proc "DEBUG"))
(define info (make-prefixed-log-proc "INFO"))
(define warning (make-prefixed-log-proc "WARNING"))
(define error (make-prefixed-log-proc "ERROR"))
